import pymysql

# 连接mysql(socket)
conn = pymysql.connect(host="127.0.0.1", port=3306, user='root', passwd='', charset='utf8')
cursor = conn.cursor()

# 1.查看数据库
# 发送指令
# cursor.execute("show databases")
#
# # 获取指令的结果
# result = cursor.fetchall()  # 接受返回的值
# print(result)

# 2.创建数据库(新增、删除、修改)
# 发送指令
# cursor.execute("create database db3 default charset utf8 collate utf8_general_ci")
# conn.commit()

# 获取指令的结果
# result1 = cursor.fetchall() # 接受返回的值
# print(result1)

# 删除数据库
# cursor.execute("drop database db3")
# cursor.execute("drop database study1")
# conn.commit()

# cursor.execute("show databases")
# result2 = cursor.fetchall()
# print(result2)

# 5.进入数据库，查看表
# cursor.execute("use mysql")
# cursor.execute("show tables")
# result = cursor.fetchall()
# print(result)

# 关闭连接
cursor.close()
conn.close()
